package com.institute.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import com.institute.entity.Institute;
import com.institute.entity.Position;
import com.staff.entity.Staff;

@Repository
public interface InstituteRepository extends PagingAndSortingRepository<Institute,Long>,JpaSpecificationExecutor<Institute>{
	@Query(value="from Institute i where i.name = ?1")
	public Institute findByDeptName(String name);
	@Query(value="from Institute i where i.father.id = ?1")
	public List<Institute> findChildren(Long id);
	@Query(value="from Staff s where s.department.id = ?1")
	public List<Staff> findStaffsByDept(Long id);
	@Query(value="from Position p where p.dept.id = ?1")
	public List<Position> findPositions(Long id);
	@Query(value="from Institute i where i.principal.id = ?1")
	public Institute findByPrincipal(Long staffId);
	@Query(value="from Institute i where i.father = null")
	public List<Institute> findRootInstitutes();
	@Query(value="from Staff s where s.id = ?1")
	public Staff findPrincipal(Long principalId);
}
